package com.qf;



import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;

import java.io.IOException;

/**
 * 获取Es链接的工具类
 */
public class EsClient {
    public static RestClient restClient = RestClient.builder(new HttpHost("127.0.0.1", 9200)).build();
    public static ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
    public static ElasticsearchClient client = new ElasticsearchClient(transport);

    public static ElasticsearchClient client() {
        return client;
    }

    public static void clientOff() throws IOException {
        // 关闭连接
        transport.close();
        restClient.close();
    }

}
